package com.qqt.csr.archive.service;


import com.qqt.csr.archive.entity.reader.ArtificialConversation;
import com.qqt.csr.archive.mapper.ArtificialConversationMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * @Author: yang hao
 * @Date: 2024/11/19 16:21
 * @Description: 归档会话服务
 **/
@Slf4j
@Service
public class ArtificialConversationService {

    @Autowired
    private ArtificialConversationMapper artificialConversationMapper;
    @Autowired
    private ArtificialMessageService artificialMessageService;

    /**
     * 根据id查询会话
     * @param id {@link String} 会话id
     * @return {@link ArtificialConversation} 会话
     */
    public ArtificialConversation getById(String id) {
        Optional<ArtificialConversation> conversation = artificialConversationMapper.findById(id);
        conversation.ifPresent(c->{
            Integer swMsgCount = artificialMessageService.countSensitiveWordMsgCountBy(c.getId());
            c.setSensitiveWordMsgCount(swMsgCount);
        });
        return conversation.orElse(null);
    }


    /**
     * 根据id集合查询会话集合
     * @param ids {@link List<String>} 会话id集合
     * @return {@link List<ArtificialConversation>} 会话集合
     */
    public List<ArtificialConversation> getByIds(List<String> ids) {
        if (ids == null || ids.isEmpty()) {
            return Collections.emptyList();
        }
        return artificialConversationMapper.findAllById(ids);
    }

}
